<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <j-form-container :disabled="formDisabled">
        <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
          <a-row>
            <a-col :span="24">
              <a-form-model-item label="发生事件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="eventCode">
                <j-dict-select-tag :disabled="czType=='2'" @getKeyValue="selectChange" type="list" v-model="model.eventCode" dictCode="two_reward_type" placeholder="请选择发生事件" />
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="旗下等级" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="eventGrade">
<!--                <a-input v-model="model.eventGrade" placeholder="请输入旗下等级"  ></a-input>-->
                <a-select :disabled="czType=='2'" v-if="model.parentGrade<4" v-model="model.eventGrade" placeholder="请输入旗下等级">
                  <a-select-option v-for="item in (parseInt(model.parentGrade)-1)" :key="item" :value="item">
                    {{item}}
                  </a-select-option>
                </a-select>
                <a-select :disabled="czType=='2'" v-else v-model="model.eventGrade" placeholder="请输入旗下等级">
                  <a-select-option v-for="item in (parseInt(model.parentGrade))" :key="item" :value="item">
                    {{item}}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="二级佣金比例(%)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rate">
                <a-input-number :min="0" style="width: 100%" v-model="model.rate" placeholder="请输入二级佣金比例"  ></a-input-number>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </j-form-container>
    </a-spin>
  </j-modal>
</template>

<script>
  export default {
    name: 'RewardTwoModal',
    components: {
    },
    data () {
      return {
        title:'',
        width:800,
        visible: false,
        disableSubmit: false,
        formDisabled:false,
        model:{
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          eventCode: [
            { required: true, message: '请选择发生事件!'},
          ],
          eventGrade: [
            { required: true, message: '请选择旗下等级!'},
          ],
          rate: [
            { required: true, message: '请输入二级佣金比例!'},
          ],
        },
        url: {
          add: "/system/rewardTwo/add",
          edit: "/system/rewardTwo/edit",
          queryById: "/system/rewardTwo/queryById"
        },
        czType:"",//1、新增 2、更新
      }
    },
    created () {
    },
    methods: {
      add (record) {
        this.visible=true
        this.edit(record);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        var that=this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            if(this.czType=='1'){
              this.$emit('itemAdd',this.model);
            }else if(this.czType=='2'){
              this.$emit('itemUpdate',this.model);
            }
            this.close();
          }
        })

      },
      submitCallback(){
        this.$emit('ok');
        this.visible = false;
      },
      handleCancel () {
        this.close()
      },
      selectChange(item){
        this.model.eventName=item.text;
      }
    }
  }
</script>